home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / asy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  3.7 KB  |  153 lines

  1. #include <stdio.h>
  2. #include <ctype.h>        /* used for 'tolower' */
  3. #include "global.h"
  4. #include "config.h"
  5. #ifdef ASY
  6. #include "iface.h"
  7. #include "pktdrvr.h"
  8. #include "netuser.h"
  9. #include "asy.h"
  10. #include "8250.h"
  11. #include "ax25.h"
  12. #include "kiss.h"
  13. #include "slip.h"
  14. #include "nrs.h"
  15. #include "proc.h"
  16. #include "commands.h"
  17.  
  18. /* Attach a serial interface to the system
  19.  * argv[0]: hardware type, must be "asy"
  20.  * argv[1]: I/O address, e.g., "0x3f8"
  21.  * argv[2]: vector, e.g., "4"
  22.  * argv[3]: mode, may be:
  23.  *        "slip" (point-to-point SLIP)
  24.  *        "ax25" (AX.25 frame format in SLIP for raw TNC)
  25.  *        "nrs" (NET/ROM format serial protocol)
  26.  * argv[4]: interface label, e.g., "sl0"
  27.  * argv[5]: receiver ring buffer size in bytes
  28.  * argv[6]: maximum transmission unit, bytes
  29.  * argv[7]: interface speed, e.g, "9600"
  30.  * argv[8]: optional flags, e.g., 'c' for cts flow control, 'v' for Van
  31.  *        Jacobson TCP header compression (slip only)
  32.  */
  33. int
  34. asy_attach(argc,argv,p)
  35. int argc;
  36. char *argv[];
  37. void *p;
  38. {
  39.     struct iface *if_asy;
  40.     int dev, xdev, trigchar = -1;
  41.     char cts;
  42.  
  43. #ifdef AX25
  44.     if(*Mycall == '\0') {
  45.         tputs(Nomycall);
  46.         return -1;
  47.     }
  48. #endif
  49.  
  50.     if(if_lookup(argv[4]) != NULLIF) {
  51.         tprintf(Ifexist,argv[4]);
  52.         return -1;
  53.     }
  54.  
  55.     /* Find unused asy control block */
  56.     for(dev = 0; dev < ASY_MAX; dev++) {
  57.         if(Asy[dev].iface == NULLIF)
  58.             break;
  59.     }
  60.     if(dev >= ASY_MAX){
  61.         tprintf("Max %d async controllers\n",ASY_MAX);
  62.         return -1;
  63.     }
  64.  
  65.     for(xdev = 0;xdev < SLIP_MAX;xdev++){
  66.         if(Slip[xdev].iface == NULLIF)
  67.             break;
  68.     }
  69.     if(xdev >= SLIP_MAX) {
  70.         tprintf("Max %d slip/asy/nrs devices\n",SLIP_MAX);
  71.         return -1;
  72.     }
  73.  
  74.     /* Create interface structure and fill in details */
  75.     if_asy = (struct iface *)mxallocw(sizeof(struct iface));
  76.     if_asy->addr = Ip_addr;
  77.     if_asy->name = strxdup(argv[4]);
  78.     if_asy->mtu = atoi(argv[6]);
  79.     if_asy->dev = dev;
  80.     if_asy->stop = asy_stop;
  81.  
  82.     switch(tolower(*argv[3])) {
  83. #ifdef    SLIP
  84.     case 's':
  85.         setencap(if_asy,"SLIP");
  86.         if_asy->ioctl = asy_ioctl;
  87.         if_asy->raw = slip_raw;
  88.         if_asy->xdev = xdev;
  89.  
  90.         Slip[xdev].iface = if_asy;
  91.         Slip[xdev].send = asy_send;
  92.         Slip[xdev].get = get_asy;
  93.         Slip[xdev].type = CL_SERIAL_LINE;
  94.         trigchar = FR_END;
  95.         if_asy->proc = newproc("asy rx",256,asy_rx,xdev,NULL,NULL,0);
  96.         break;
  97. #endif
  98. #ifdef    AX25
  99.     case 'a':
  100.         setencap(if_asy,"AX25");
  101.         if_asy->ioctl = kiss_ioctl;
  102.         if_asy->raw = kiss_raw;
  103.         if_asy->xdev = xdev;
  104.         if_asy->port = 0;
  105.  
  106.         if_asy->hwaddr = strxdup(Mycall);
  107.         init_maxheard(if_asy);
  108.         init_flags(if_asy);
  109.  
  110.         Slip[xdev].iface = if_asy;
  111.         Slip[xdev].kiss[if_asy->port] = if_asy;        /* G1EMM */
  112.         Slip[xdev].send = asy_send;
  113.         Slip[xdev].get = get_asy;
  114.         Slip[xdev].type = CL_KISS;
  115.         trigchar = FR_END;
  116.         if_asy->proc = newproc("asy rx",256,asy_rx,xdev,NULL,NULL,0);
  117.         break;
  118. #endif
  119. #ifdef    NRS
  120.     case 'n':
  121.         setencap(if_asy,"AX25");
  122.         if_asy->ioctl = asy_ioctl;
  123.         if_asy->raw = nrs_raw;
  124.         if_asy->xdev = xdev;
  125.  
  126.         if_asy->hwaddr = strxdup(Mycall);
  127.         init_maxheard(if_asy);
  128.         init_flags(if_asy);
  129.  
  130.         Nrs[xdev].iface = if_asy;
  131.         Nrs[xdev].send = asy_send;
  132.         Nrs[xdev].get = get_asy;
  133.         trigchar = ETX;
  134.         if_asy->proc = newproc("nrs rx",256,nrs_recv,xdev,NULL,NULL,0);
  135.         break;
  136. #endif
  137.     default:
  138.         tprintf("Mode %s unknown for interface %s\n",argv[3],argv[4]);
  139.         xfree(if_asy->name);
  140.         xfree((char *)if_asy);
  141.         return -1;
  142.     }
  143.     if_asy->proc1 = newproc("asy tx",256,asy_tx,dev,NULL,NULL,0);
  144.     if_asy->niface = Niface++;
  145.     if_asy->next = Ifaces;
  146.     Ifaces = if_asy;
  147.     cts = (argc < 8) ? 0 : (*argv[8] == 'c') ? 1 : 0;
  148.     asy_init(dev,if_asy,argv[1],argv[2],(unsigned)atoi(argv[5]),trigchar,cts);
  149.     asy_speed(dev,atol(argv[7]));
  150.     return 0;
  151. }
  152.  
  153. #endif /* ASY */